package com.householditemtwo.index.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.householditemtwo.common.entity.Carousel;
import com.householditemtwo.common.entity.Designer;
import com.householditemtwo.common.entity.News;
import com.householditemtwo.common.entity.Newstype;
import com.householditemtwo.common.entity.Product;
import com.householditemtwo.common.utils.DBManager;
import com.householditemtwo.common.utils.QueryDataResult;

public class NewsContentDao {
	//查询出新闻分类
	public List<Newstype> selectNewstype() {
		DBManager db=new DBManager();
		String sql="select * from newstype  ";
		QueryDataResult qdr=db.executeQuery(sql);
		Carousel emp=new Carousel();
		ArrayList<Newstype> list=new ArrayList<Newstype>();
		try {
			while(qdr.rs.next()) {
				Newstype c=new Newstype();
				c.setNewstypeid(qdr.rs.getInt(1));
				c.setNewstypename(qdr.rs.getString(2));
				list.add(c);
			}
		}catch(SQLException e) {
			e.printStackTrace();
		}
		
		//返回查询的结果
		return list;
		
	}
	
	//查询出新闻详情内容
		public List<News> selectNews() {
			DBManager db=new DBManager();
			String sql="select * from news order by newsTime desc ";
			QueryDataResult qdr=db.executeQuery(sql);
			Carousel emp=new Carousel();
			ArrayList<News> list=new ArrayList<News>();
			try {
				while(qdr.rs.next()) {
					News c=new News();
				   c.setNewsid(qdr.rs.getInt(1));
				   c.setNewstitle(qdr.rs.getString(2));
				   c.setNewscontent(qdr.rs.getString(3));
				   c.setNewsdetails(qdr.rs.getString(4));
				   c.setNewstypeid(qdr.rs.getInt(5));
				   c.setNewstime(qdr.rs.getString(6));
				   c.setNewsclick(qdr.rs.getInt(7));
				   c.setNewschoice(qdr.rs.getString(8));
				   c.setNewsimg(qdr.rs.getString(9));
				   list.add(c);
				}
			}catch(SQLException e) {
				e.printStackTrace();
			}
			
			//返回查询的结果
			return list;
			
		}
	
		/**
		 * 查询某个产品分类的所有产品
		 * @return
		 */
			public News selectNewsById(int newsid){
				DBManager db=new DBManager();
				String sql="select * from news where newsid="+newsid;
				QueryDataResult qdr=db.executeQuery(sql);
				News c=new News();
				try {
					while(qdr.rs.next()) {
						//创建出Producttype，并且给它属性附值
					
						 c.setNewsid(qdr.rs.getInt(1));
						   c.setNewstitle(qdr.rs.getString(2));
						   c.setNewscontent(qdr.rs.getString(3));
						   c.setNewsdetails(qdr.rs.getString(4));
						   c.setNewstypeid(qdr.rs.getInt(5));
						   c.setNewstime(qdr.rs.getString(6));
						   c.setNewsclick(qdr.rs.getInt(7));
						   c.setNewschoice(qdr.rs.getString(8));
						   c.setNewsimg(qdr.rs.getString(9));
						
					}
				}catch(SQLException e) {
					e.printStackTrace();
				}
				
				//返回查询的结果
				return c;
			}
	
	
	
}
